#include "stdafx.h"
#include "config_context.h"

#include <fstream>

using namespace std;

void ConfigContent::LoadConfig()
{
    std::ifstream file;
    std::wstring app_dir = nbase::win32::GetCurrentModuleDirectory();
#ifdef _DEBUG
    file.open(app_dir + L"cefSimple_config", ios::in | ios::binary);
#else
    file.open(app_dir + L"config", ios::in | ios::binary);
#endif
    if (file.is_open())
    {
        string s;
        char buff[4096] = { 0 };
        while (file >> buff)
            s.append(buff);

        Json::Reader reader;
        Json::Value value;
        if (reader.parse(s, value) && value.isObject())
        {
            if (value["main_url"].isString())
                main_url_ = value["main_url"].asString();
            if (value["offline_url"].isString())
                offline_url_ = value["offline_url"].asString();
            if (value["debug"].isBool())
                can_debug_ = value["debug"].asBool();
            if (value["toolbar"].isBool())
                have_toolbar_ = value["toolbar"].asBool();
        }
        file.close();
    }

}